package com.scorpionstudio.girlstoryshop.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.loopj.android.image.SmartImageView;
import com.scorpionstudio.girlstoryshop.R;
import com.scorpionstudio.girlstoryshop.bean.ItemGridMain;

import java.util.List;

public class MainAdapter extends ArrayAdapter<ItemGridMain> {
    private LayoutInflater mInflater;

    public MainAdapter(Context context, int textViewResourceId,
                       List<ItemGridMain> objects) {
        super(context, textViewResourceId, objects);
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder mHolder;
        ItemGridMain mItemGridMain = this.getItem(position);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_grid_main, parent, false);
            mHolder = new ViewHolder();
            mHolder.imgName = (TextView) convertView.findViewById(R.id.tv_grid_main);
            mHolder.mImg = (SmartImageView) convertView.findViewById(R.id.img_icon_cate);
            convertView.setTag(mHolder);
        } else {
            mHolder = (ViewHolder) convertView.getTag();
        }

        mHolder.imgName.setText(mItemGridMain.getImgName());
        mHolder.mImg.setImageResource(mItemGridMain.getIconId());
        return convertView;
    }

    class ViewHolder {
        TextView imgName;
        SmartImageView mImg;
    }

}
